//
//  Triangle.m
//  测试VIEW旋转45度
//
//  Created by yishangpin2 on 15/3/9.
//  Copyright (c) 2015年 yishangpin2. All rights reserved.
//

#import "Triangle.h"

@implementation Triangle

- (void)drawRect:(CGRect)rect {
    
    //设置背景颜色
    [[UIColor clearColor]set];
    UIRectFill([self bounds]);
    //拿到当前视图准备好的画板
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    //利用path进行绘制三角形
    CGContextBeginPath(context);//标记
    CGContextMoveToPoint(context, 0, 0);//设置起点
    CGContextAddLineToPoint(context, self.frame.size.height, 0);
    CGContextAddLineToPoint(context, self.frame.size.height, self.frame.size.height);
    CGContextClosePath(context);//路径结束标志，不写默认封闭
    [[UIColor orangeColor] setFill]; //设置填充色
    [[UIColor whiteColor] setStroke]; //设置边框颜色
    CGContextDrawPath(context, kCGPathFillStroke);//绘制路径path
    
    
    //调用旋转
    [self Rotate];

}


#pragma mark - 旋转整个VIEW

-(void)Rotate{
    //旋转,左旋90度
    CGAffineTransform rotate = CGAffineTransformMakeRotation(-90 / 180.0 * M_PI );
    
    [self setTransform:rotate];
    
    //旋转,右旋45度
    CGAffineTransform rotate1 = CGAffineTransformMakeRotation(45 / 180.0 * M_PI );
    
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(self.frame.size.width/3.5,self.frame.size.width/7.5, 25, 15)];
    
    
    label.text = @"-80%";
    
    label.textColor = [UIColor whiteColor];
    label.adjustsFontSizeToFitWidth = YES;

    
    label.font = [UIFont fontWithName:@"Helvetica-Bold" size:10];
    
    
    [label setTransform:rotate1];
    
    [self addSubview:label];


}
@end
